package com.ruoyi.web.controller.monitor;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.monitor.domain.BusWaterAutomonitorDaydata;
import com.ruoyi.monitor.service.IBusWaterAutomonitorDaydataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水监测日数据Controller
 * 
 * @author ruoyi
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/monitor/autodaydata")
public class BusWaterAutomonitorDaydataController extends BaseController
{
    @Autowired
    private IBusWaterAutomonitorDaydataService busWaterAutomonitorDaydataService;

    /**
     * 查询水监测日数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWaterAutomonitorDaydata busWaterAutomonitorDaydata)
    {
        startPage();
        List<BusWaterAutomonitorDaydata> list = busWaterAutomonitorDaydataService.selectBusWaterAutomonitorDaydataList(busWaterAutomonitorDaydata);
        return getDataTable(list);
    }

    /**
     * 导出水监测日数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:export')")
    @Log(title = "水监测日数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterAutomonitorDaydata busWaterAutomonitorDaydata)
    {
        List<BusWaterAutomonitorDaydata> list = busWaterAutomonitorDaydataService.selectBusWaterAutomonitorDaydataList(busWaterAutomonitorDaydata);
        ExcelUtil<BusWaterAutomonitorDaydata> util = new ExcelUtil<BusWaterAutomonitorDaydata>(BusWaterAutomonitorDaydata.class);
        util.exportExcel(response, list, "水监测日数据数据");
    }

    /**
     * 获取水监测日数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:query')")
    @GetMapping(value = "/{mn}")
    public AjaxResult getInfo(@PathVariable("mn") String mn)
    {
        return success(busWaterAutomonitorDaydataService.selectBusWaterAutomonitorDaydataByMn(mn));
    }

    /**
     * 新增水监测日数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:add')")
    @Log(title = "水监测日数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterAutomonitorDaydata busWaterAutomonitorDaydata)
    {
        return toAjax(busWaterAutomonitorDaydataService.insertBusWaterAutomonitorDaydata(busWaterAutomonitorDaydata));
    }

    /**
     * 修改水监测日数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:edit')")
    @Log(title = "水监测日数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusWaterAutomonitorDaydata busWaterAutomonitorDaydata)
    {
        return toAjax(busWaterAutomonitorDaydataService.updateBusWaterAutomonitorDaydata(busWaterAutomonitorDaydata));
    }

    /**
     * 删除水监测日数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autodaydata:remove')")
    @Log(title = "水监测日数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mns}")
    public AjaxResult remove(@PathVariable String[] mns)
    {
        return toAjax(busWaterAutomonitorDaydataService.deleteBusWaterAutomonitorDaydataByMns(mns));
    }

    /**
     * 水质日历详情
     * @param id
     * @return
     */
    @GetMapping("/statisCalendarDetail")
    public AjaxResult statisCalendarDetail(String id,String day){
        return AjaxResult.success(busWaterAutomonitorDaydataService.statisCalendarDetail(id,day));
    }

    /**
     * 周报
     * @param id
     * @return
     */
    @GetMapping("/weeklyReport")
    public AjaxResult weeklyReport(String id,String startTime,String endTime){
        Date startDate = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",startTime+" 00:00:00");
        Date endDate = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",endTime+" 23:59:59");
        return AjaxResult.success(busWaterAutomonitorDaydataService.weeklyReport(id, startDate,endDate));
    }

    /**
     * 月报
     * @param id
     * @return
     */
    @GetMapping("/yearReport")
    public AjaxResult yearReport(String id,String year){
        Date startDate = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",year+"-01-01 00:00:00");
        Date endDate = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",year+"-12-31 23:59:59");
        return AjaxResult.success(busWaterAutomonitorDaydataService.yearReport(id, startDate,endDate));
    }
}
